From fc001b14c00f530d106400149b9be69837d6952f Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 15 Nov 2024 12:37:54 +0200 Subject: Mostly finished the custom markdown blog, still tweaking a bit --- src/pages/blogs/[...slug].astro | 53 +++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'src/pages/blogs/[...slug].astro') diff --git a/src/pages/blogs/[...slug].astro b/src/pages/blogs/[...slug].astro index b8fa5b4..dbd6b80 100644 --- a/src/pages/blogs/[...slug].astro +++ b/src/pages/blogs/[...slug].astro @@ -7,14 +7,20 @@ import TerminalBorder from "@components/TerminalBorder.astro"; export async function getStaticPaths() { const blogEntries = await getCollection("blogs"); - return blogEntries.map((entry) => ({ - params: { slug: entry.slug }, - props: { entry }, + return blogEntries.map((blog) => ({ + params: { slug: blog.slug }, + props: { entry: blog }, })); } const { entry } = Astro.props; const { Content } = await entry.render(); + +const blogs = await getCollection("blogs"); +const sortedBlogs = blogs.sort((a, b) => +b.data.date - +a.data.date); +const currentIndex = sortedBlogs.findIndex((blog) => blog.slug === entry.slug); +const previousBlog = sortedBlogs[currentIndex + 1] || undefined; +const nextBlog = sortedBlogs[currentIndex - 1] || undefined; --- @@ -30,18 +36,35 @@ const { Content } = await entry.render();
-
- - - vim ~/blogs/next-blog.md - - - vim ~/blogs/next-blog.md - +
+ { + previousBlog ? ( + + + + vim ~/blogs/{previousBlog.slug}.md + + + + ) : ( +
-- cgit v1.3.1